package com.service.scheduling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.mapper.CoinsMapper;
import com.service.dao.model.Coins;
import com.service.scheduling.service.CoinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年09月27日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@Service
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class CoinServiceImpl extends ServiceImpl<CoinsMapper, Coins> implements CoinService {

    @Override
    public Map<String, BigDecimal> listCoinFee() {
        return baseMapper.selectAllByStatus(CommonStatusEnums.ACTIVE.getCode()).stream()
                .collect(Collectors.toMap(Coins::getCoinName, Coins::getCoinFee));
    }


    @Override
    public Integer isTransfer(Integer coinId){
        Coins coins = baseMapper.selectById(coinId);
        return coins.getTransfer();
    }

    @Override
    public Coins getByCoinsName(String coin) {
        return getOne(new LambdaQueryWrapper<Coins>().eq(Coins::getCoinName, coin)
                .eq(Coins::getCoinStatus, CommonStatusEnums.ACTIVE.getCode()).last("limit 1"));
    }
}
